'use strict';

goog.provide('Blockly.Blocks.mago');

goog.require('Blockly.Blocks');

// Color
// Blockly.Blocks.mago.HUE = 195;
var magoColor_base = '#406398';  //基础
var magoColor_music = '#DB8CCD'; //音乐
var magoColor_dis = '#51acff';   //显示
var magoColor_time = '#EC6E68';  //时钟
var magoColor_car = '#406398';   //电机驱动
var magoColor_ps2 = '#47C5CA';   //PS2遥控
// 未使用色彩
//ED157A - FF66B6
//E5B646 - FFCC66

/********************************************
BASE - 基础模块
*********************************************/
Blockly.Blocks.mg_base_loop = {
  init: function() {
    this.setColour(magoColor_time);
    this.appendDummyInput()
    .appendField("循环运行(一直运行)");
    this.appendStatementInput('DO')
    .appendField('');
    this.setTooltip("该模块可用可不用，不会影响程序运行");
  }
};
Blockly.Blocks.mg_base_setup = {
  init: function() {
    this.setColour(magoColor_time);
    this.appendDummyInput()
    .appendField("初始化(开机运行一次)");
    this.appendStatementInput('DO')
    .appendField('');
    this.setTooltip("初始化(开机运行一次)");
  }
};

Blockly.Blocks.controls_delay_second = {
  init: function() {
   this.setColour(magoColor_base);
   this.appendValueInput("DELAY_TIME", Number)
   .appendField("延时s(秒)")
   .setCheck(Number);
   this.setPreviousStatement(true, null);
   this.setNextStatement(true, null);
   this.setInputsInline(true);
   this.setTooltip("1000ms(毫秒)=1s(秒)");
 }
};

// PWM
Blockly.Blocks.mg_pwm = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField(Blockly.MIXLY_ANALOGWRITE)
      .appendField(new Blockly.FieldImage("../../media/mago/mg_pwm.png", 71, 32))
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.appendValueInput("NUM", Number)
      .appendField(Blockly.MIXLY_VALUE2)
      .setCheck(Number);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip(Blockly.MIXLY_TOOLTIP_INOUT_ANALOG_WRITE);
  }
};

// Buzzer active - 有源蜂鸣器
Blockly.Blocks.mg_buzzer = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField(Blockly.MIXLY_YF_BUZZER)
      .appendField(new Blockly.FieldImage("../../media/mago/mg_buzzer_p.png", 50, 32));
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.appendValueInput("STAT")
      .appendField(Blockly.MIXLY_STAT)
      .setCheck([Number, Boolean]);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
  }
};



//DHT11 - 温湿度传感器
Blockly.Blocks.mg_dht = {
  init: function () {
    var WHAT = [[Blockly.MIXLY_GETTEMPERATUE, 'temperature'], [Blockly.MIXLY_GETHUMIDITY, 'humidity']];
    this.setColour(Blockly.Blocks.sensor.HUE);
    this.appendDummyInput("")
    .appendField(new Blockly.FieldDropdown([['DHT11', '11'], ['DHT21', '21'], ['DHT22', '22']]), 'TYPE')
    .appendField(Blockly.MIXLY_PIN)
    .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN")
    .appendField(new Blockly.FieldDropdown(WHAT), "WHAT");
    this.setOutput(true, Number);
    var thisBlock = this;
    this.setTooltip(function () {
      var op = thisBlock.getFieldValue('WHAT');
      var TOOLTIPS = {
        'temperature': Blockly.MIXLY_TOOLTIP_BLOCKGROUP_GET_TEM,
        'humidity': Blockly.MIXLY_TOOLTIP_BLOCKGROUP_GET_HUM
      };
      return TOOLTIPS[op];
    });
  }
};

//微动开关
Blockly.Blocks.mg_microswitch = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("按键")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_microSwitch.png", 44, 32));
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.setOutput(true, [Boolean, Number]);
    this.setInputsInline(true);
    this.setTooltip("请使用串口读取按键的按下值");
  }
};


//触摸
Blockly.Blocks.mg_touchsensor = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("触摸模块")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_touch.png", 44, 32));
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.setOutput(true, [Boolean, Number]);
    this.setInputsInline(true);
    this.setTooltip("请使用串口读取触摸模块值");
  }
};
//红外避障
Blockly.Blocks.mg_Infraredsensor = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("红外避障模块")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_Infraredsensor.png", 44, 32));
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.setOutput(true, [Boolean, Number]);
    this.setInputsInline(true);
    this.setTooltip("请使用串口读取红外避障模块值");
  }
};
//光敏电阻
Blockly.Blocks.mg_lightsensor = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("光敏电阻模块")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_photo.png", 44, 32));
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.setOutput(true, [Boolean, Number]);
    this.setInputsInline(true);
    this.setTooltip("请使用串口读取光敏电阻模块值");
  }
};
//人体感应
Blockly.Blocks.mg_bodysensor = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("人体感应模块")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mg_bodysensor.png", 44, 32));
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.setOutput(true, [Boolean, Number]);
    this.setInputsInline(true);
    this.setTooltip("请使用串口读取人体感应模块值");
  }
};
//水滴
Blockly.Blocks.mg_rainsensor = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("水滴检测模块")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_raindrop.png", 44, 32));
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.setOutput(true, [Boolean, Number]);
    this.setInputsInline(true);
    this.setTooltip("请使用串口读取水滴检测模块值");
  }
};

// led开
Blockly.Blocks.mg_ledon = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("LED开")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_ledon.png", 71, 32))
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip("");
  }
};
// led关
Blockly.Blocks.mg_ledoff = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("LED关")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_ledoff.png", 71, 32))
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip("");
  }
};
// ledpwm
Blockly.Blocks.mg_ledpwm = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("LED亮度PWM调节")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mg_ledpwm.png", 71, 32))
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.appendValueInput("speed", Number)
      .appendField("亮度(0~255)")
      .setCheck(Number);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip("0:不亮,255:最亮");
  }
};

// 蜂鸣器开
Blockly.Blocks.mg_buzzeron = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("蜂鸣器开")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mg_buzzer.png", 71, 32))
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip("");
  }
};
// 蜂鸣器关
Blockly.Blocks.mg_buzzeroff = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("蜂鸣器关")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mg_buzzer.png", 71, 32))
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip("");
  }
};

// 单个电机
// Motor direction - 电机转向
var YF_MD = [['正转', '1'], ['反转', '0']];
Blockly.Blocks.mg_singlemotor = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mg_motor.png", 71, 32));
    this.appendDummyInput()
      .appendField(" ")
      .appendField(new Blockly.FieldDropdown(YF_MD), 'DIR');
    this.appendValueInput("PIN1", Number)
      .appendField("管脚1")
      .setCheck(Number);
    this.appendValueInput("PIN2", Number)
      .appendField("管脚2")
      .setCheck(Number);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip("");
  }
};
// 单个电机
Blockly.Blocks.mg_singlemotor_stop = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mg_motor.png", 71, 32));
    this.appendDummyInput()
      .appendField(" ")
      .appendField("停止");
    this.appendValueInput("PIN1", Number)
      .appendField("管脚1")
      .setCheck(Number);
    this.appendValueInput("PIN2", Number)
      .appendField("管脚2")
      .setCheck(Number);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip("");
  }
};

// 单个电机调速
Blockly.Blocks.mg_singlemotorpwm1 = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mg_motor.png", 71, 32));
    this.appendDummyInput()
      .appendField(" ")
      .appendField(new Blockly.FieldDropdown(YF_MD), 'DIR');
    this.appendValueInput("PIN1", Number)
      .appendField("PWM管脚1")
      .setCheck(Number);
    this.appendValueInput("PIN2", Number)
      .appendField("管脚2")
      .setCheck(Number);
    this.appendValueInput("speed", Number)
      .appendField("速度(0~255)")
      .setCheck(Number);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip("");
  }
};


// motor开
Blockly.Blocks.mg_motor1on = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("普通电机开")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mg_motor2.png", 71, 32));
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip("");
  }
};
// motor关
Blockly.Blocks.mg_motor1off = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("普通电机关")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mg_motor2.png", 71, 32));
    this.appendValueInput("PIN", Number)
      .appendField(Blockly.MIXLY_PIN)
      .setCheck(Number);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip("");
  }
};
// motorpwm
Blockly.Blocks.mg_motor1pwm = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mg_motor2.png", 71, 32));
    this.appendDummyInput()
      .appendField(" ")
      .appendField(new Blockly.FieldDropdown(YF_MD), 'DIR');
    this.appendValueInput("PIN1", Number)
      .appendField("PWM管脚1")
      .setCheck(Number);
    this.appendValueInput("PIN2", Number)
      .appendField("管脚2")
      .setCheck(Number);
    this.appendValueInput("speed", Number)
      .appendField("速度(0~255)")
      .setCheck(Number);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip("");
  }
};

//蜂鸣器频率
var TONE_NOTES = [
  ["NOTE_C5", "532"],
 ["NOTE_D5", "587"],
 ["NOTE_E5", "659"],
 ["NOTE_F5", "698"],
 ["NOTE_G5", "784"],
 ["NOTE_A5", "880"],
 ["NOTE_B5", "988"],
 ["NOTE_C6", "1048"],
 ["NOTE_D6", "1176"],
 ["NOTE_E6", "1320"],
 ["NOTE_F6", "1396"],
 ["NOTE_G6", "1568"],
 ["NOTE_A6", "1760"],
 ["NOTE_B6", "1976"],
 ["NOTE_C7", "2096"],
 ["NOTE_D7", "2352"],
 ["NOTE_E7", "2640"],
 ["NOTE_F7", "2792"],
 ["NOTE_G7", "3136"],
 ["NOTE_A7", "3520"],
 ["NOTE_B7", "3952"]];

//执行器-蜂鸣器的频率选择
Blockly.Blocks.MAKER17_tone_notes = {
 init: function() {
   this.setColour(magoColor_base);
   this.appendDummyInput("").appendField(new Blockly.FieldDropdown(TONE_NOTES), 'STAT');
  this.setOutput(true, Number);
 }
};

//执行器-蜂鸣器模块
Blockly.Blocks.MAKER17_tone = {
 init: function() {
   this.setColour(magoColor_base);
   this.appendDummyInput("").appendField(new Blockly.FieldImage("../../media/mago/mago/mg_buzzer.png",  60,50)).appendField("蜂鸣器");
   this.appendValueInput("PIN", Number).appendField(Blockly.MIXLY_PIN).setCheck(Number);
   this.appendValueInput('FREQUENCY').setCheck(Number).appendField(Blockly.MIXLY_FREQUENCY);
   this.appendValueInput('DURATION', Number).setCheck(Number).appendField(Blockly.MIXLY_DURATION).appendField("(ms)");
   this.setInputsInline(true);
   this.setPreviousStatement(true);
   this.setNextStatement(true);
 }
};

//执行器-蜂鸣器停止模块
Blockly.Blocks.MAKER17_newNoTone = {
 init: function() {
   this.setColour(magoColor_base);
   this.appendDummyInput("").appendField(new Blockly.FieldImage("../../media/mago/mago/mg_buzzer.png",  60,50)).appendField("结束声音");
   this.appendValueInput("PIN", Number).appendField(Blockly.MIXLY_PIN).setCheck(Number);
   this.appendValueInput("DELAY_TIME", Number).appendField(Blockly.MIXLY_DELAY).setCheck(Number).appendField("(ms)");
   this.setInputsInline(true);
   this.setPreviousStatement(true);
   this.setNextStatement(true);
 }
};






Blockly.Blocks.mg_varspeedservo = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField(Blockly.MIXLY_SERVO)
      .appendField(new Blockly.FieldImage("../../media/mago/mago/servo.png", 60, 50))
      .appendField(Blockly.MIXLY_PIN)
      .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN");

    this.appendValueInput("DEGREE", Number)
      .setCheck(Number)
      .appendField(Blockly.MIXLY_DEGREE_0_180);

    this.appendValueInput("SPEED", Number)
      .setCheck(Number)
      .appendField(Blockly.MIXLY_SPEED);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip('');
  }
};
Blockly.Blocks.mg_varspeedservobywait = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("等待舵机移动完成")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/servo.png", 60, 50))
      .appendField(Blockly.MIXLY_PIN)
      .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN");

    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip('');
  }
};
Blockly.Blocks.mg_varspeedservobystop = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("将舵机停在当前位置")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/servo.png", 60, 50))
      .appendField(Blockly.MIXLY_PIN)
      .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN");

    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setInputsInline(true);
    this.setTooltip('');
  }
};
Blockly.Blocks.mg_varspeedservobydegree = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField(Blockly.MIXLY_SERVO)
      .appendField(new Blockly.FieldImage("../../media/mago/mago/servo.png", 60, 50))
      .appendField(Blockly.MIXLY_PIN)
      .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN")
      .appendField(Blockly.MIXLY_READ_DEGREES);

    this.setOutput(true, [Boolean, Number]);
    this.setInputsInline(true);
    this.setTooltip('');
  }
};


//for
Blockly.Blocks.mg_make_for = {
  init: function () {
    this.appendValueInput("variate")
      .setCheck(null)
      .appendField("for(");
    this.appendValueInput("judge")
      .setCheck(null)
      .appendField(";");
    this.appendValueInput("operation")
      .setCheck(null)
      .appendField(";");
    this.appendDummyInput()
      .appendField(")");
    this.appendStatementInput("do")
      .setCheck(null)
      .appendField("执行");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(magoColor_base);
    this.setTooltip("for循环");
    this.setHelpUrl("");
  }
};



Blockly.Blocks.make_tool_normal = {
  init: function () {
    this.appendValueInput("data")
      .setCheck(null);
    this.setInputsInline(false);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(magoColor_base);
    this.setTooltip("");
    this.setHelpUrl("");
  }
};

//初始化舵机
Blockly.Blocks.make_arduino_servo_begin = {
  init: function () {
    this.appendDummyInput()
      .appendField(new Blockly.FieldImage("../../media/mago/mago/servo.png", 60, 50))
      .appendField("连接舵机")
      .appendField(new Blockly.FieldTextInput("servo"), "name");
    this.appendValueInput("pin")
      .setCheck(null)
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField(" 到管脚#");
    this.setInputsInline(true);
    this.setOutput(true, null);
    this.setColour(magoColor_base);
    this.setTooltip(
      "1.功能:\n"
      + "->初始化舵机，成功返回通道号，失败则返回0\n"
      + "2.语法:\n"
      + "->uint8_t attach(int pin)\n"
      + "3.参数:\n"
      + "->pin:所连接的控制管脚\n"
      + "4.返回值:uint8_t型数据"
    );
    this.setHelpUrl("");
  }
};

//初始化舵机 可设置最小角度和最大角度
Blockly.Blocks.make_arduino_servo_begin_1 = {
  init: function () {
    this.appendDummyInput()
      .appendField(new Blockly.FieldImage("../../media/mago/mago/servo.png", 60, 50))
      .appendField("连接舵机")
      .appendField(new Blockly.FieldTextInput("servo"), "name");
    this.appendValueInput("pin")
      .setCheck(null)
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField(" 到管脚#");
    this.appendValueInput("min")
      .setCheck(null)
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField("最小脉宽");
    this.appendValueInput("max")
      .setCheck(null)
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField("微秒 最大脉宽");
    this.appendDummyInput()
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField("微秒");
    this.setInputsInline(true);
    this.setOutput(true, null);
    this.setColour(magoColor_base);
    this.setTooltip(
      "1.功能:\n"
      + "->初始化舵机，成功返回通道号，失败则返回0\n"
      + "2.语法:\n"
      + "->uint8_t attach(int pin, int min, int max)\n"
      + "3.参数:\n"
      + "->pin:所连接的控制管脚\n"
      + "->min:最小脉冲宽度\n"
      + "->max:最大脉冲宽度\n"
      + "4.返回值:uint8_t型数据"
    );
    this.setHelpUrl("");
  }
};

//舵机 设置角度
Blockly.Blocks.make_arduino_servo_write = {
  init: function () {
    this.appendDummyInput()
      .appendField(new Blockly.FieldImage("../../media/mago/mago/servo.png", 60, 50))
      .appendField("舵机")
      .appendField(new Blockly.FieldTextInput("servo"), "name");
    this.appendValueInput("value")
      .setCheck(null)
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField(" 角度设为");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(magoColor_base);
    this.setTooltip(
      "1.功能:\n"
      + "->舵机 设置当前的角度(0~180°)，输入值超出544视为脉冲宽度，小于则视为角度，不阻塞程序运行\n"
      + "2.语法:\n"
      + "->void write(int value)\n"
      + "3.参数:\n"
      + "->value:脉冲宽度或角度值\n"
      + "4.返回值:无"
    );
    this.setHelpUrl("");
  }
};

//舵机 设置角度和速度
Blockly.Blocks.make_arduino_servo_write_1 = {
  init: function () {
    this.appendDummyInput()
      .appendField(new Blockly.FieldImage("../../media/mago/mago/servo.png", 60, 50))
      .appendField("舵机")
      .appendField(new Blockly.FieldTextInput("servo"), "name");
    this.appendValueInput("value")
      .setCheck(null)
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField(" 角度设为");
    this.appendValueInput("speed")
      .setCheck(null)
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField("速度");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(magoColor_base);
    this.setTooltip(
      "1.功能:\n"
      + "->舵机 设置当前的角度(0~180°)，输入值超出544视为脉冲宽度，小于则视为角度，不阻塞程序运行\n"
      + "2.语法:\n"
      + "->void write(int value, uint8_t speed)\n"
      + "3.参数:\n"
      + "->value:脉冲宽度或角度值\n"
      + "->speed:从初始位置到目标位置之间的速度(0~255)，0时为全速\n"
      + "4.返回值:无"
    );
    this.setHelpUrl("");
  }
};

//舵机 设置角度和速度以及选择是否阻塞
Blockly.Blocks.make_arduino_servo_write_2 = {
  init: function () {
    this.appendDummyInput()
      .appendField(new Blockly.FieldImage("../../media/mago/mago/servo.png", 60, 50))
      .appendField("舵机")
      .appendField(new Blockly.FieldTextInput("servo"), "name");
    this.appendValueInput("value")
      .setCheck(null)
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField(" 角度设为");
    this.appendValueInput("speed")
      .setCheck(null)
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField("速度");
    this.appendValueInput("wait")
      .setCheck(null)
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField("等待完成?");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(magoColor_base);
    this.setTooltip(
      "1.功能:\n"
      + "->舵机 设置当前的角度(0~180°)，输入值超出544视为脉冲宽度，小于则视为角度\n"
      + "2.语法:\n"
      + "->void write(int value, uint8_t speed, bool wait)\n"
      + "3.参数:\n"
      + "->value:脉冲宽度或角度值\n"
      + "->speed:从初始位置到目标位置之间的速度(0~255)，0时为全速\n"
      + "->wait:是否阻塞程序的运行\n"
      + "4.返回值:无"
    );
    this.setHelpUrl("");
  }
};

//舵机 设置脉冲宽度
Blockly.Blocks.make_arduino_servo_writeMicroseconds = {
  init: function () {
    this.appendValueInput("value")
      .setCheck(null)
      .appendField(new Blockly.FieldImage("../../media/mago/mago/servo.png", 60, 50))
      .appendField("舵机")
      .appendField(new Blockly.FieldTextInput("servo"), "name")
      .appendField(" 脉宽设为");
    this.appendDummyInput()
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField("微秒");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(magoColor_base);
    this.setTooltip(
      "1.功能:\n"
      + "->舵机 设置脉冲宽度，默认的最小脉宽为544微秒，最大脉宽为2400微秒\n"
      + "2.语法:\n"
      + "->void writeMicroseconds(int value)\n"
      + "3.参数:\n"
      + "->value:脉冲宽度\n"
      + "4.返回值:无"
    );
    this.setHelpUrl("");
  }
};

//舵机 获取数据
Blockly.Blocks.make_arduino_servo_read = {
  init: function () {
    this.appendDummyInput()
      .appendField(new Blockly.FieldImage("../../media/mago/mago/servo.png", 60, 50))
      .appendField("舵机")
      .appendField(new Blockly.FieldTextInput("servo"), "name")
      .appendField(new Blockly.FieldDropdown([["获取当前角度", "read"], ["获取当前脉宽", "readMicroseconds"], ["正在移动?", "isMoving"], ["舵机连上控制管脚?", "attached"]]), "type");
    this.setInputsInline(true);
    this.setOutput(true, null);
    this.setColour(magoColor_base);
    this.setTooltip(
      "1.功能:\n"
      + "->舵机 获取当前角度、获取当前脉宽、正在移动?、舵机连上控制管脚?\n"
      + "2.语法:\n"
      + "->获取当前角度 - int read()\n"
      + "->获取当前脉宽 - int readMicroseconds()\n"
      + "->正在移动? - bool isMoving()\n"
      + "->舵机连上控制管脚? - bool attached()\n"
      + "3.参数:无\n"
      + "4.返回值:int或boolean型数据"
    );
    this.setHelpUrl("");
  }
};

//舵机 执行某些函数
Blockly.Blocks.make_arduino_servo_set = {
  init: function () {
    this.appendDummyInput()
      .appendField(new Blockly.FieldImage("../../media/mago/mago/servo.png", 60, 50))
      .appendField("舵机")
      .appendField(new Blockly.FieldTextInput("servo"), "name")
      .appendField(new Blockly.FieldDropdown([["停止移动", "stop"], ["等待移动完成", "wait"], ["停止执行动作组", "sequenceStop"], ["释放管脚", "detach"]]), "type");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(magoColor_base);
    this.setTooltip(
      "1.功能:\n"
      + "->舵机 停止移动、等待移动完成、停止执行动作组、释放管脚\n"
      + "2.语法:\n"
      + "->停止移动 - void stop()\n"
      + "->等待移动完成 - void wait()\n"
      + "->停止执行动作组 - void sequenceStop()\n"
      + "->释放管脚 - void detach()\n"
      + "3.参数:无\n"
      + "4.返回值:无"
    );
    this.setHelpUrl("");
  }
};


//TODO 智慧家居

// rgb灯
Blockly.Blocks.mg_rgb2on = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("RGB流水灯点亮")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_rgb.png", 60, 37))
    this.appendValueInput("PIN1")
      .setCheck(Number).setAlign(Blockly.ALIGN_RIGHT)
      .appendField("灯数")
    this.appendValueInput("PIN2")
      .setCheck(Number).setAlign(Blockly.ALIGN_RIGHT)
      .appendField("间隔时间")
    this.appendDummyInput("")
      .appendField("毫秒(ms)")
    this.appendDummyInput("")
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField(new Blockly.FieldColour("#99FF99"), "RGB_LED_COLOR");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
  }
};

Blockly.Blocks.mg_rgb2off = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("RGB流水灯熄灭")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_rgb.png", 60, 37))
    this.appendValueInput("PIN1")
      .setCheck(Number).setAlign(Blockly.ALIGN_RIGHT)
      .appendField("灯数")
    this.appendValueInput("PIN2")
      .setCheck(Number).setAlign(Blockly.ALIGN_RIGHT)
      .appendField("间隔时间")
    this.appendDummyInput("")
      .appendField("毫秒(ms)")
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
  }
};
Blockly.Blocks.mg_rgb2on_low = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("RGB灯呼吸效果(点亮)")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_rgb.png", 60, 37))
    this.appendValueInput("PIN1")
      .setCheck(Number).setAlign(Blockly.ALIGN_RIGHT)
      .appendField("灯数")
    this.appendDummyInput("")
      .appendField("颜色")
      .appendField(new Blockly.FieldDropdown([["红", "R"], ["绿", "G"], ["蓝", "B"], ["白", "W"]]), "COLOR")
      .appendField("渐变时间")
      .appendField(new Blockly.FieldDropdown([["慢速", "low"], ["中速", "middle"], ["快速", "fast"]]), "SPEED");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
  }
};
Blockly.Blocks.mg_rgb2off_low = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("RGB灯呼吸效果(熄灭))")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_rgb.png", 60, 37))
    this.appendValueInput("PIN1")
      .setCheck(Number).setAlign(Blockly.ALIGN_RIGHT)
      .appendField("灯数")
    this.appendDummyInput("")
      .appendField("颜色")
      .appendField(new Blockly.FieldDropdown([["红", "R"], ["绿", "G"], ["蓝", "B"], ["白", "W"]]), "COLOR")
      .appendField("渐变时间")
      .appendField(new Blockly.FieldDropdown([["慢速", "low"], ["中速", "middle"], ["快速", "fast"]]), "SPEED");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
  }
};

//水滴传感器
Blockly.Blocks.mg_raindrops = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("雨滴模块检测到水滴")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_raindrop.png", 60, 50));
    this.setOutput(true, [Boolean, Number]);
    this.setInputsInline(true);
    this.setTooltip('');
  }
};
//光照传感器
Blockly.Blocks.mg_lightcontrol = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("光控模块检测光线很暗")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_photo.png", 60, 50));
    this.setOutput(true, [Boolean, Number]);
    this.setInputsInline(true);
    this.setTooltip('');
  }
};
//触摸
Blockly.Blocks.mg_touchmodule = {
  init: function () {
    this.setColour(magoColor_base);
    this.appendDummyInput("")
      .appendField("触摸模块检测到手指")
      .appendField(new Blockly.FieldImage("../../media/mago/mago/mago_touch.png", 60, 50));
    this.setOutput(true, [Boolean, Number]);
    this.setInputsInline(true);
    this.setTooltip('');
  }
};


//舵机 设置角度和速度
Blockly.Blocks.mg_servo_write_smarthome = {
  init: function () {
    this.appendDummyInput()
      .appendField(new Blockly.FieldImage("../../media/mago/mago/servo.png", 60, 50))
      .appendField("舵机")
      .appendField(new Blockly.FieldTextInput("servo"), "name");
    this.appendValueInput("pin")
      .setCheck(null)
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField(" 到管脚#");
    this.appendValueInput("value")
      .setCheck(null)
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField(" 角度设为");
    this.appendValueInput("speed")
      .setCheck(null)
      .setAlign(Blockly.ALIGN_RIGHT)
      .appendField("速度");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(magoColor_base);
    this.setTooltip(
      "1.功能:\n"
      + "->舵机 设置当前的角度(0~180°)，输入值超出544视为脉冲宽度，小于则视为角度，不阻塞程序运行\n"
      + "2.语法:\n"
      + "->void write(int value, uint8_t speed)\n"
      + "3.参数:\n"
      + "->value:脉冲宽度或角度值\n"
      + "->speed:从初始位置到目标位置之间的速度(0~255)，0时为全速\n"
      + "4.返回值:无"
    );
    this.setHelpUrl("");
  }
};


//显示-MAX7219-初始化
Blockly.Blocks.mg_MAX7219_init = {
  init: function() {
    this.appendDummyInput("").appendField(new Blockly.FieldImage("../../media/mago/mago/matrix44.png",  60,  50));
    this.appendValueInput("PIN1").setCheck(Number).setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.MAKER17_MAX7219_INIT).appendField("DIN").appendField(Blockly.MIXLY_PIN);
    this.appendValueInput("PIN2").setCheck(Number).setAlign(Blockly.ALIGN_RIGHT).appendField("CS").appendField(Blockly.MIXLY_PIN);
    this.appendValueInput("PIN3").setCheck(Number).setAlign(Blockly.ALIGN_RIGHT).appendField("CLK").appendField(Blockly.MIXLY_PIN);
    this.appendValueInput("Intensity").setCheck(Number).setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.MAKER17_BRIGHTNESS);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(magoColor_base);
    this.setInputsInline(true);
    this.setTooltip("");
    this.setHelpUrl('');
  }
};

//显示-MAX7219-滚动字符串
Blockly.Blocks.mg_MAX7219_putString = {
  init: function() {
    this.appendDummyInput("").appendField(new Blockly.FieldImage("../../media/mago/mago/matrix44.png", 60,  50));
    this.appendValueInput("String", String).setCheck([String, Number]).setAlign(Blockly.ALIGN_RIGHT).appendField("滚动字符串");
    this.appendValueInput("Speed").setCheck(Number).setAlign(Blockly.ALIGN_RIGHT).appendField("速度");
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(magoColor_base);
    this.setInputsInline(true);
    this.setTooltip("");
    this.setHelpUrl('');
  }
};

//显示-MAX7219-清除LED点阵
// Blockly.Blocks.Ledcontrol_clearDisplay = {
//   init: function() {
//     this.appendDummyInput().appendField("清除LED点阵显示").appendField(new Blockly.FieldTextInput("LC"), "VAR");
//     this.appendValueInput("NUM").setCheck(Number).setAlign(Blockly.ALIGN_RIGHT).appendField("点阵模块编号（1~8）");
//     this.setPreviousStatement(true, null);
//     this.setNextStatement(true, null);
//     this.setColour(Blockly.Blocks.maker17.HUE3);
//     this.setInputsInline(true);
//     this.setTooltip('清除LED点阵(Max7219)显示');
//     this.setHelpUrl('');
//   }
// };
//显示-MAX7219-LED点阵显示图案
Blockly.Blocks.mg_MAX7219_DisplayChar = {
  init: function() {
    this.appendDummyInput("").appendField(new Blockly.FieldImage("../../media/mago/mago/matrix44.png", 60,50));
    this.appendDummyInput().appendField("LED点阵显示图案");
    this.appendValueInput("Chars").setCheck(Number).setAlign(Blockly.ALIGN_RIGHT);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(magoColor_base);
    this.setTooltip("");
    this.setHelpUrl('');
  }
};

//显示-max7219点阵选择数组
Blockly.Blocks.mg_LedArray = {
  init: function() {
    this.appendDummyInput("").appendField("图案变量").appendField(new Blockly.FieldTextInput("LedArray"), "VAR");
    this.appendDummyInput("").appendField(new Blockly.FieldCheckbox("FALSE"), "a11").appendField(new Blockly.FieldCheckbox("FALSE"), "a12").appendField(new Blockly.FieldCheckbox("FALSE"), "a13").appendField(new Blockly.FieldCheckbox("TRUE"), "a14").appendField(new Blockly.FieldCheckbox("TRUE"), "a15").appendField(new Blockly.FieldCheckbox("FALSE"), "a16").appendField(new Blockly.FieldCheckbox("FALSE"), "a17").appendField(new Blockly.FieldCheckbox("FALSE"), "a18");
    this.appendDummyInput("").appendField(new Blockly.FieldCheckbox("FALSE"), "a21").appendField(new Blockly.FieldCheckbox("FALSE"), "a22").appendField(new Blockly.FieldCheckbox("FALSE"), "a23").appendField(new Blockly.FieldCheckbox("TRUE"), "a24").appendField(new Blockly.FieldCheckbox("TRUE"), "a25").appendField(new Blockly.FieldCheckbox("FALSE"), "a26").appendField(new Blockly.FieldCheckbox("FALSE"), "a27").appendField(new Blockly.FieldCheckbox("FALSE"), "a28");
    this.appendDummyInput("").appendField(new Blockly.FieldCheckbox("TRUE"), "a31").appendField(new Blockly.FieldCheckbox("TRUE"), "a32").appendField(new Blockly.FieldCheckbox("TRUE"), "a33").appendField(new Blockly.FieldCheckbox("TRUE"), "a34").appendField(new Blockly.FieldCheckbox("TRUE"), "a35").appendField(new Blockly.FieldCheckbox("TRUE"), "a36").appendField(new Blockly.FieldCheckbox("TRUE"), "a37").appendField(new Blockly.FieldCheckbox("TRUE"), "a38");
    this.appendDummyInput("").appendField(new Blockly.FieldCheckbox("TRUE"), "a41").appendField(new Blockly.FieldCheckbox("FALSE"), "a42").appendField(new Blockly.FieldCheckbox("FALSE"), "a43").appendField(new Blockly.FieldCheckbox("TRUE"), "a44").appendField(new Blockly.FieldCheckbox("TRUE"), "a45").appendField(new Blockly.FieldCheckbox("FALSE"), "a46").appendField(new Blockly.FieldCheckbox("FALSE"), "a47").appendField(new Blockly.FieldCheckbox("TRUE"), "a48");
    this.appendDummyInput("").appendField(new Blockly.FieldCheckbox("TRUE"), "a51").appendField(new Blockly.FieldCheckbox("TRUE"), "a52").appendField(new Blockly.FieldCheckbox("TRUE"), "a53").appendField(new Blockly.FieldCheckbox("TRUE"), "a54").appendField(new Blockly.FieldCheckbox("TRUE"), "a55").appendField(new Blockly.FieldCheckbox("TRUE"), "a56").appendField(new Blockly.FieldCheckbox("TRUE"), "a57").appendField(new Blockly.FieldCheckbox("TRUE"), "a58");
    this.appendDummyInput("").appendField(new Blockly.FieldCheckbox("FALSE"), "a61").appendField(new Blockly.FieldCheckbox("FALSE"), "a62").appendField(new Blockly.FieldCheckbox("FALSE"), "a63").appendField(new Blockly.FieldCheckbox("TRUE"), "a64").appendField(new Blockly.FieldCheckbox("TRUE"), "a65").appendField(new Blockly.FieldCheckbox("FALSE"), "a66").appendField(new Blockly.FieldCheckbox("FALSE"), "a67").appendField(new Blockly.FieldCheckbox("FALSE"), "a68");
    this.appendDummyInput("").appendField(new Blockly.FieldCheckbox("FALSE"), "a71").appendField(new Blockly.FieldCheckbox("FALSE"), "a72").appendField(new Blockly.FieldCheckbox("FALSE"), "a73").appendField(new Blockly.FieldCheckbox("TRUE"), "a74").appendField(new Blockly.FieldCheckbox("TRUE"), "a75").appendField(new Blockly.FieldCheckbox("FALSE"), "a76").appendField(new Blockly.FieldCheckbox("FALSE"), "a77").appendField(new Blockly.FieldCheckbox("FALSE"), "a78");
    this.appendDummyInput("").appendField(new Blockly.FieldCheckbox("FALSE"), "a81").appendField(new Blockly.FieldCheckbox("FALSE"), "a82").appendField(new Blockly.FieldCheckbox("FALSE"), "a83").appendField(new Blockly.FieldCheckbox("TRUE"), "a84").appendField(new Blockly.FieldCheckbox("TRUE"), "a85").appendField(new Blockly.FieldCheckbox("FALSE"), "a86").appendField(new Blockly.FieldCheckbox("FALSE"), "a87").appendField(new Blockly.FieldCheckbox("FALSE"), "a88");
    this.setOutput(true, Number);
    this.setColour(magoColor_base);
    this.setTooltip('');
    this.setHelpUrl('');
  }
};

//显示-MAX7219-LED点阵图案
Blockly.Blocks.mg_Max7219_img = {
  init: function() {
    this.appendDummyInput("").appendField("预设图案").appendField(new Blockly.FieldDropdown([
      ["↑", "183c7edb18181818"],
      ["↓", "18181818db7e3c18"],
      ["←", "103060ffff603010"],
      ["→", "080c06ffff060c08"],
      ["♥", "42e7ffffff7e3c18"],
      ["▲", "183c7eff00000000"],
      ["▼", "00000000ff7e3c18"],
      ["◄", "103070f0f0703010"],
      ["►", "080c0e0f0f0e0c08"],
      ["△", "182442ff00000000"],
      ["▽", "00000000ff422418"],
      ["☺", "3c42a581a599423c"],
      ["○", "3c4281818181423c"],
      ["◑", "3c4e8f8f8f8f4e3c"],
      ["◐", "3c72f1f1f1f1723c"],
      ["￥", "4224ff08ff080808"],
      ["Χ", "8142241818244281"],
      ["✓", "0000010204885020"],
      ["□", "007e424242427e00"],
      ["▣", "007e425a5a427e00"],
      ["◇", "1824428181422418"],
      ["♀", "3844444438107c10"],
      ["♂", "0f030579d888d870"],
      ["♪", "0c0e0b080878f860"],
      ["✈", "203098ffff983020"],
      ["卍", "00f21212fe90909e"],
      ["卐", "009e9090fe1212f2"],
      ["︱", "1010101010101010"],
      ["—", "000000ff00000000"],
      ["╱", "0102040810204080"],
      ["＼", "8040201008040201"],
      ["大", "1010fe1010284482"],
      ["中", "1010fe9292fe1010"],
      ["小", "1010105454921070"],
      ["米", "00925438fe385492"],
      ["正", "00fe10105e5050fc"],
      ["囧", "ffa5a5c3bda5a5ff"]
    ]), "img_");
    this.setOutput(true);
    this.setTooltip('');
    this.setColour(magoColor_base);
    this.setHelpUrl('');
  }
};

//红外接收模块
Blockly.Blocks.mg_ir_recv = {
    init: function () {
        this.setColour(Blockly.Blocks.communicate.HUE);
        this.appendValueInput("PIN", Number)
        .appendField(new Blockly.FieldTextInput('ir_item'), 'VAR')
        .appendField(Blockly.MIXLY_IR_RECEIVE)
        .setCheck(Number);
        this.appendStatementInput('DO')
        .appendField(Blockly.MIXLY_IR_RECEIVE_YES);
        this.appendStatementInput('DO2')
        .appendField(Blockly.MIXLY_IR_RECEIVE_NO);
        this.setPreviousStatement(true);
        this.setNextStatement(true);
        this.setInputsInline(true);
        this.setTooltip(Blockly.MIXLY_IR_RECIEVE_TOOLTIP);
    },
    getVars: function () {
        return [this.getFieldValue('VAR')];
    },
    renameVar: function (oldName, newName) {
        if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
            this.setTitleValue(newName, 'VAR');
        }
    }
};
//红外发射模块（NEC）
Blockly.Blocks.ir_send_nec = {
    init: function () {
        var TYPE = [['RC5', 'RC5'], ['RC6', 'RC6'], ['NEC', 'NEC'], ['Sony', 'Sony'], ['Panasonic', 'Panasonic'], ['JVC', 'JVC'], ['SAMSUNG', 'SAMSUNG'], ['Whynter', 'Whynter'], ['AiwaRCT501', 'AiwaRCT501'], ['LG', 'LG'], ['Sanyo', 'Sanyo'], ['Mitsubishi', 'Mitsubishi'], ['DISH', 'DISH'], ['SharpRaw', 'SharpRaw'], ['Denon', 'Denon']];
        this.setColour(Blockly.Blocks.communicate.HUE);
        this.appendDummyInput("")
        .appendField(Blockly.MIXLY_IR_SEND_NEC1)
        .appendField(new Blockly.FieldDropdown(TYPE), 'TYPE')
        .appendField(Blockly.MIXLY_IR_SEND_NEC2)
        .appendField(new Blockly.FieldDropdown([["3", "3"]]), "PIN");
        this.appendValueInput('data')
        .setCheck(Number)
        .appendField(' ' + Blockly.MIXLY_DATA);
        this.appendValueInput('bits')
        .setCheck(Number)
        .appendField(' ' + Blockly.MIXLY_BITS);
        this.setPreviousStatement(true);
        this.setNextStatement(true);
        this.setInputsInline(true);
        this.setTooltip(Blockly.MIXLY_IR_SEND_NEC_TOOLTIP);
    }
}

//红外接收使能
Blockly.Blocks.ir_recv_enable = {
    init: function () {
        this.setColour(Blockly.Blocks.communicate.HUE);
        this.appendValueInput("PIN", Number)
        .appendField(Blockly.MIXLY_IR_RECEIVE_ENABLE);
        this.setPreviousStatement(true);
        this.setNextStatement(true);
        this.setInputsInline(true);
        this.setTooltip(Blockly.MIXLY_TOOLTIP_IR_ENABLE);
    }
};

//红外接收模块(raw)
Blockly.Blocks.mg_ir_recv_raw = {
    init: function () {
        this.setColour(Blockly.Blocks.communicate.HUE);
        this.appendValueInput("PIN", Number)
        .appendField(Blockly.MIXLY_IR_RECEIVE_RAW)
        .setCheck(Number);
        this.setPreviousStatement(true);
        this.setNextStatement(true);
        this.setInputsInline(true);
        this.setTooltip(Blockly.MIXLY_IR_RECIEVE_RAW_TOOLTIP);
    }
};

//红外发射模块(raw)
Blockly.Blocks.mg_ir_send_raw = {
    init: function () {
        this.setColour(Blockly.Blocks.communicate.HUE);
        this.appendDummyInput("")
        .appendField(Blockly.MIXLY_IR_SEND_RAW)
        .appendField(new Blockly.FieldDropdown([["3", "3"]]), "PIN");
        this.appendDummyInput("")
        .appendField(' ' + Blockly.MIXLY_I2C_SLAVE_WRITE_ARRAY_ARRAYNAME)
        .appendField(new Blockly.FieldTextInput('0,0,0'), 'TEXT');
        this.appendValueInput('length')
        .setCheck(Number)
        .appendField(' ' + Blockly.MIXLY_LIST_LENGTH);
        this.appendValueInput('freq')
        .setCheck(Number)
        .appendField(' ' + Blockly.MIXLY_FREQUENCY);
        this.setInputsInline(true);
        this.setPreviousStatement(true);
        this.setNextStatement(true);
        this.setTooltip(Blockly.MIXLY_IR_SEND_RAW_TOOLTIP);
    }
};